package cn.toma.core.web;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author zqx
 * @version 1.0.0
 * @ClassName CaptchaConfig.java
 * @Description API 验证码配置
 * @createTime 2019年09月23日 09:14:00
 */
@Configuration
public class CaptchaConfig
{

	/**
	 * API 验证码参数配置
	 */
	@Bean
	public DefaultKaptcha captcha()
	{
		Properties properties = new Properties();
		properties.put("kaptcha.border", "no");
		properties.put("kaptcha.border.color", "105,179,90");
		properties.put("kaptcha.textproducer.font.color", "black");
		properties.put("kaptcha.image.width", "170");
		properties.put("kaptcha.image.height", "50");
		properties.put("kaptcha.textproducer.font.size", "45");
		properties.put("kaptcha.session.key", "code");
		properties.put("kaptcha.textproducer.char.length", "4");
		properties.put("kaptcha.textproducer.char.string", "0123456789");
		properties.put("kaptcha.textproducer.font.names", "宋体,楷体");
		properties.put("kaptcha.background.clear.to", "white");
		Config config = new Config(properties);
		DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
		defaultKaptcha.setConfig(config);
		return defaultKaptcha;
	}
}
